import java.util.*;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

public class Thread65 {
    public static void main4(String[] args) {
        ArrayList<Integer>b=new ArrayList<>();
        Stack<Integer>c=new Stack<>();



    }
    public static void main5(String[] args) throws InterruptedException{
        Semaphore a=new Semaphore(1);
        a.acquire();
        System.out.println("申请一个资源空间");
        a.release();
        System.out.println("释放一个资源空间");

    }
    public static void main2(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock(true);
        reentrantLock.tryLock();
    }







    public static void main1(String[] args)throws InterruptedException {
        AtomicInteger count=new AtomicInteger(0);
        Thread t1=new Thread(()->{
            for(int i=0;i<5000;i++)
            {
                //count.getAndIncrement();//相当于count++
                //count.incrementAndGet();
                count.addAndGet(2);
            }

        });
        t1.start();
        Thread t2=new Thread(()->{
            for(int j=0;j<5000;j++)
            {
                //count.getAndIncrement();
                //count.getAndDecrement();
                count.incrementAndGet();
            }

        });
        t2.start();
        t1.join();
        t2.join();
        System.out.println(count);



    }
}
